sap.ui.define([
    'jquery.sap.global',
    'sap/m/bbf41/Module/controller/BaseController',
    'sap/ui/model/json/JSONModel',
    'sap/m/MessageToast'
], function (jQuery, BaseController, JSONModel, MessageToast) {
    "use strict";
    var AppController = BaseController.extend("sap.m.bbf41.Module.controller.Welcome", {
        onInit: function () {
            var sPath = jQuery.sap.getModulePath("sap.m.bbf41.Module", "/data/webapp_list.json");
            var oModel = new JSONModel(sPath);
            var oView = this.getView();
            oView.setModel(oModel);

            var oRouter = this.getRouter();
            oRouter.attachRouteMatched(function (oEvent) {
                var routeName = oEvent.getParameter('name').toLowerCase();
                if (routeName == 'welcome') {
                    oView.setModel(oModel);
                }
            });
        },
        openWebApp: function (oEvent) {
            var oContext = oEvent.getSource().getBindingContext();
            var sPath = oContext.getPath();
            var oProperty = oContext.getModel().getProperty(sPath);
            if (oProperty) {
                if (oProperty.route) {
                    this.getRouter().navTo(oProperty.route);
                }
                else if (oProperty.url) {
                    location.href = oProperty.url;
                }
                else {
                    MessageToast.show("The page is under construction.");
                }
            }
        }
    });
    return AppController;
});
